Skip to content

Refactor cleanup to separate clean.sh script and add clean job to e2e.yml workflow#250

Merged
pelikhan merged 3 commits into
mainfrom
copilot/fix-937d5d9d-549d-414a-8744-1c4ed8e552c9
Sep 22, 2025
Merged

Refactor cleanup to separate clean.sh script and add clean job to e2e.yml workflow#250
pelikhan merged 3 commits into
mainfrom
copilot/fix-937d5d9d-549d-414a-8744-1c4ed8e552c9

Conversation

Copilot AI commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

This PR refactors test resource cleanup by moving it from the e2e.sh script to a dedicated clean.sh script and integrating it as a prerequisite job in the CI workflow, addressing safety concerns and improving separation of concerns.

Problem

The e2e.sh script previously performed cleanup of test resources (closing issues, PRs, deleting branches) by default on every run. This could be problematic when:

  • Running tests in environments where cleanup isn't desired
  • Debugging test failures where preserving test artifacts is helpful
  • Running tests where cleanup might interfere with concurrent processes

Solution

Refactored the cleanup functionality into a separate script and CI job:

# Clean script runs independently
./clean.sh

# E2E script focuses only on testing
./e2e.sh

# CI workflow runs cleanup before tests automatically

Key Changes

1. Separate clean.sh Script

  • Created dedicated cleanup script with all previous cleanup functionality
  • Includes detailed logging and error handling for each resource type
  • Self-contained with authentication checks and proper exit codes
  • Can be run independently for manual cleanup operations

2. Updated CI Workflow (e2e.yml)

  • Added new clean job that runs before all e2e tests
  • Executes clean.sh with proper GitHub CLI authentication
  • Uploads cleanup logs as artifacts for debugging
  • All e2e test jobs now depend on the clean job completion

3. Simplified e2e.sh

  • Removed all cleanup functionality and --clean flag
  • Script now focuses solely on test execution
  • Cleaner command-line interface without cleanup options
  • Better separation of concerns between testing and cleanup

4. Enhanced Logging

The cleanup script provides detailed logging for transparency:

🧹 GitHub Agentic Workflows Test Resource Cleanup
==================================================
ℹ️  Cleaning up test resources...
ℹ️  Checking for open issues to close...
ℹ️  Closed issue #123
ℹ️  Closed issue #124
ℹ️  Checking for open pull requests to close...
ℹ️  Closed pull request #45
ℹ️  Checking for test branches to delete...
ℹ️  Deleted branch: test-pr-feature-branch
✅ Cleanup completed: 2 issues closed, 1 PRs closed, 1 branches deleted

Workflow Changes

Before: E2E tests handled their own cleanup optionally
After: Dedicated cleanup job runs before all tests automatically

This ensures:

  • Consistent cleanup behavior across all CI runs
  • Better isolation between cleanup and testing phases
  • Easier debugging with separate logs for cleanup operations
  • Ability to run cleanup independently when needed

Testing

All functionality has been verified:

  • clean.sh script syntax and functionality validated
  • e2e.sh cleanup code properly removed and --clean flag rejected
  • CI workflow structure updated with proper job dependencies
  • Both scripts have correct executable permissions
  • Dry run mode and other e2e.sh functionality preserved

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot

  • move the cleaning code in a separate script "clean.sh"
  • add a "clean" job in e2e.yml that runs cleaned.sh
  • make all other jobs "needs" the clean job

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] - make cleaning of test resources optional in the e2e.sh script - add logging"--clean" flag to enable, default is false. - add logging for cleaned resources Add optional cleanup with --clean flag and enhanced logging to e2e.sh Sep 22, 2025
Copilot AI requested a review from pelikhan September 22, 2025 10:04
….yml

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

  • move the cleaning code in a separate script "clean.sh"...

I've implemented all the requested changes in commit 46bb965:

  1. Moved cleaning code to separate clean.sh script - Extracted all cleanup functionality with detailed logging and authentication checks
  2. Added "clean" job in e2e.yml - New job runs clean.sh before tests and uploads cleanup logs as artifacts
  3. Made all other jobs depend on clean job - Added needs: clean to ensure cleanup runs first

The cleanup is now completely separated from the test logic, running as a prerequisite CI job. The e2e.sh script is now focused solely on testing, and the --clean flag has been removed since cleanup happens automatically in CI.

Copilot AI changed the title Add optional cleanup with --clean flag and enhanced logging to e2e.sh Refactor cleanup to separate clean.sh script and add clean job to e2e.yml workflow Sep 22, 2025
@pelikhan pelikhan marked this pull request as ready for review September 22, 2025 10:13
@github-actions

Copy link
Copy Markdown

Closed by e2e test cleanup

@github-actions github-actions Bot closed this Sep 22, 2025
@pelikhan pelikhan reopened this Sep 22, 2025
@pelikhan pelikhan merged commit 0933538 into main Sep 22, 2025
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants